package com.ohc.leetcode.链表;

import java.util.*;

/**
 * 2022年6月22日14:10:08
 * https://leetcode.cn/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof/
 */
public class 剑指Offer25合并两个排序的链表 {
    public static class ListNode {
        int val;
       ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val,ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    private static ListNode createNode(List<Integer> list) {
        ListNode h = new ListNode(0);
        ListNode head = new ListNode(0);
        h.next = head;
        for (Integer num : list) {
            System.out.println("num = " + num);
            ListNode temp = new ListNode(num);
            head.next = temp;
            head = temp;
        }

        return h.next.next;
    }

    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ArrayList<Integer> list1 = new ArrayList<>();
        while (l1 != null) {
            list1.add(l1.val);
            l1 = l1.next;
        }
        while (l2 != null) {
            list1.add(l2.val);
            l2 = l2.next;
        }
        list1.sort((o1, o2) -> o1 - o2);
        ListNode node = createNode(list1);
        return node;
    }

    public static void main(String[] args) {
        TreeMap<Integer, Object> treeMap = new TreeMap<>();
        treeMap.put(5, null);
        treeMap.put(6, null);
        treeMap.put(4, null);
        treeMap.put(2, null);
        treeMap.put(1, null);
        Set<Map.Entry<Integer, Object>> entries = treeMap.entrySet();
        Iterator<Map.Entry<Integer, Object>> iterator = entries.iterator();
        while (iterator.hasNext()) {
            Map.Entry<Integer, Object> next = iterator.next();
            Integer key = next.getKey();
            System.out.println("key = " + key);
        }
    }

}
